package com.qingzhu.messageserver.domain.entity

import com.qingzhu.common.domain.shared.msg.constant.CreatorType
import com.qingzhu.common.domain.shared.msg.value.Content
import org.springframework.data.annotation.Id
import org.springframework.data.elasticsearch.annotations.DateFormat
import org.springframework.data.elasticsearch.annotations.Field
import org.springframework.data.elasticsearch.annotations.FieldType
import java.time.Instant

/**
 * ChatMessage entity in elasticsearch
 * 和 common 包的 Message 一样结构，只是为了es存储
 */
data class ChatMessage(
    /** 公司id */
    val organizationId: Int,
    /** ChatMessage uuid */
    @Id
    val uuid: String,
    /** Ordered ID generated by the server */
    val seqId: Long,
    @Field(type = FieldType.Date, format = DateFormat.date_time)
    val createdAt: Instant = Instant.now(),
    /** 会话id */
    var conversationId: Long?,
    /** 消息来源 (服务器设置) */
    var from: Long,
    /** 消息送至 */
    var to: Long,
    /** 消息类型 接收者类型 */
    val type: CreatorType,
    /** 创建者类型 */
    val creatorType: CreatorType,
    /** 内容 */
    @Field(type = FieldType.Object)
    val content: Content,
    /** 昵称 */
    val nickName: String? = null,
)